package com.MartynovichIgor.KnowledgeTest.tools.filetools;
import java.io.*;
import java.util.ArrayList;

/**
 * Created by:
 * User: Igor Martynovich and Guzenko Igor
 * Date: 05.11.13
 */
public class FileSaver {
       private String fileName;
       public FileSaver(String fileName)
       {
           this.fileName = fileName;
       }
       public void cleanFile() throws FileNotFoundException {
           PrintWriter writer = new PrintWriter(fileName);
           writer.print("");
           writer.close();
       }

       public void writeInFile(ArrayList<String> writeText) throws FileNotFoundException {
           for (String line : writeText) {
               writeNewLine(line);
           }

       }

       public void writeNewLine(String line) throws FileNotFoundException {
           PrintStream out = new PrintStream(new BufferedOutputStream(new FileOutputStream(fileName, true)));
           out.println(line);
           out.close();

       }

        public void rewriteAllFile(ArrayList<String> infoToRewrite) throws FileNotFoundException {
            cleanFile();
            writeInFile(infoToRewrite);
        }
}
